package com.blog.zip.controller;

import com.blog.zip.bean.RespBean;
import com.blog.zip.bean.User;
import com.blog.zip.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
public class LoginController {

    @Autowired
    private UserMapper userMapper;

    @PostMapping("/login")
    public RespBean login(@RequestParam("email") String email,
                          @RequestParam("password") String password,
                          Map<String, Object> map, HttpSession session) {
        //"123456".equals(password)
        if (!StringUtils.isEmpty(email) && !StringUtils.isEmpty(password)) {
            // 通过用户名密码找到当前用户
            User user = userMapper.getUserByPassword(email, password);

            return new RespBean(200, 20000, "login success");
        } else {
            return new RespBean(301, 20000, "login fail");
        }
    }

    /**
     * 使用github登陆
     *
     * @return
     */
    @PostMapping("/login/github")
    public RespBean loginByGithub() {
        return new RespBean(200, "login success");
    }
}
